package com.icloud.system.boot;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

@Slf4j
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = "com.icloud")
@EnableFeignClients(basePackages = {"com.icloud.**.api.**.feign"})
@MapperScan({"com.icloud.**.mapper", "com.icloud.**.dao"})
public class IcloudSystemBootApplication {

	// todo
	public static void main(String[] args) throws UnknownHostException {
		ConfigurableApplicationContext application = SpringApplication.run(IcloudSystemBootApplication.class,args);
		Environment env = application.getEnvironment();

		String ip = InetAddress.getLocalHost().getHostAddress();
		String port = env.getProperty("server.port");
		String path = env.getProperty("server.servlet.context-path");
		if(Objects.isNull(path)){
			log.info("\n----------------------------------------------------------\n\t" +
					"【SystemBoot】，服务启动正在运行！访问URL:\n\t" +
					"接口调用地址: \thttp://" + ip + ":" + port + "/\n\t" +
					"----------------------------------------------------------");
		}else{
			log.info("\n----------------------------------------------------------\n\t" +
					"【SystemBoot】，服务启动正在运行！访问URL:\n\t" +
					"接口调用地址: \thttp://" + ip + ":" + port + "/" + path + "/\n\t" +
					"----------------------------------------------------------");
		}
	}

}
